package javaTest;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
//import java.lang.reflect.Method;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.junit.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;

public class DriverClass{
	static WebDriver driver;
	static BufferedWriter bw = null;
	static BufferedWriter bw1 = null;
	static String htmlname;
	static String objType;
	static String objName;
	static String TestData;
	static String rootPath;
	static int report;
	static String exeStatus = "True";

	Date cur_dt = null;
	static String filenamer;
	static String TestReport;
	int rowcnt;
	static int iflag = 0;
	static int j = 0;

	static String fireFoxBrowser;
	static String chromeBrowser;

	static String result;
	static String dataTablePath = null;
	static int intRowCount = 0;
	@Test
	public void test() throws Exception {

	String dataTablePath = "C:/Users/alubana/Google Drive/Framework/Configration/Configration.xls";
		
		String recData[][] = null;
		recData = Library_file.readData(dataTablePath, "Sheet1");
		//String scriptName = null;
		String strResultPath = null;
		for(int i = 1; i <recData.length; i ++){
			String run_NoRun = recData[i][1];

			if(run_NoRun.equalsIgnoreCase("Yes")){
				String testScriptName = recData[i][2];	
				cur_dt = new Date(); 
				DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
				String strTimeStamp = dateFormat.format(cur_dt);
				
				String ReportsPath ="C:/Users/alubana/Google Drive/Framework/Results/";


				if (ReportsPath == "") { // if results path is passed as null, by
					// default 'C:\' drive is used
					ReportsPath = "C:\\";
				}

				if (ReportsPath.endsWith("\\")) { // checks whether the path ends with
					// '/'
					ReportsPath = ReportsPath + "\\";
				}

				strResultPath = ReportsPath + "Log" + "/"  + "/" +testScriptName + "/"; //@Updated by shahid 10/08/2013
				htmlname = ReportsPath + "Log" + "/" + "/" + testScriptName + "/" + testScriptName + "_" + strTimeStamp //@Updated by shahid 10/08/2013
						+ ".html";
				File f = new File(strResultPath);
				f.mkdirs();

				bw = new BufferedWriter(new FileWriter(htmlname));

				bw.write("<HTML><BODY><TABLE BORDER=0 CELLPADDING=3 CELLSPACING=1 WIDTH=100%>");
				bw.write("<TABLE BORDER=0 BGCOLOR=BLACK CELLPADDING=3 CELLSPACING=1 WIDTH=100%>");
				bw.write("<TR><TD BGCOLOR=#66699 WIDTH=27%><FONT FACE=VERDANA COLOR=WHITE SIZE=2><B>Test Case Name:</B></FONT></TD><TD COLSPAN=6 BGCOLOR=#66699><FONT FACE=VERDANA COLOR=WHITE SIZE=2><B>"
						+ "TestCase Name" + "</B></FONT></TD></TR>");
				bw.write("<HTML><BODY><TABLE BORDER=1 CELLPADDING=3 CELLSPACING=1 WIDTH=100%>");
				bw.write("<TR COLS=7><TD BGCOLOR=#FFCC99 WIDTH=3%><FONT FACE=VERDANA COLOR=BLACK SIZE=2><B>Row</B></FONT></TD>"
						+ "<TD BGCOLOR=#FFCC99 WIDTH=10%><FONT FACE=VERDANA COLOR=BLACK SIZE=2><B>Step Name</B></FONT></TD>"
						+ "<TD BGCOLOR=#FFCC99 WIDTH=10%><FONT FACE=VERDANA COLOR=BLACK SIZE=2><B>Execution Time</B></FONT></TD> "
						+ "<TD BGCOLOR=#FFCC99 WIDTH=10%><FONT FACE=VERDANA COLOR=BLACK SIZE=2><B>Status</B></FONT></TD>"
						+ "<TD BGCOLOR=#FFCC99 WIDTH=47%><FONT FACE=VERDANA COLOR=BLACK SIZE=2><B>Detailed Report</B></FONT></TD></TR>");

				//driver = new FirefoxDriver();

				//driver.close();
				bw.close();

			}else{
				System.out.println("In confugaration field test script in line number " + i + ", name " + recData[i][2] + " is skipped Execution. ");
			}

		}

	}
}

